<?php
namespace Library;

use \Org\Util\Wechat;
use Library\Wx;

/**
 * 微信卡券操作类，上传图片
 *
 * @author pufan
 */
class WxCard {
    private static $_instance;
    
    public function __clone(){
        trigger_error('Clone is not allow!', E_USER_ERROR);
    }
    
    public static function getInstance(){
        if (!(self::$_instance instanceof self)) {
            self::$_instance = new self();
        }
        
        return self::$_instance;
    }
    public function trimall($str)//删除空格  
    {  
        $qian=array(" ","　","\t","\n","\r");  
             $hou=array("","","","","");  
        return str_replace($qian,$hou,$str);      
    }  

    public function create($path) {
        
//        $path = '@/Users/pufan/www/cmfx/data/upload/20160429/5722fa265cc93.jpg';
//        $data = array( 
//            'media' => new \CURLFile($path), 
//        ); 
        //上传图片
        //$result = $this->wechat->uploadImg($data);
        
        $card_json = '{ 
                "card": {
                   "card_type": "GROUPON",
                   "groupon": {
                       "base_info": {
                           "logo_url": "http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zHN0CwngnQY7zb7g/0",
                           "brand_name":"海底捞",
                           "code_type":"CODE_TYPE_TEXT",
                           "title": "132元双人火锅套餐",
                           "sub_title": "周末狂欢必备",
                           "color": "Color010",
                           "notice": "使用时向服务员出示此券",
                           "service_phone": "020-88888888",
                           "description": "不可与其他优惠同享\n如需团购券发票，请在消费时向商户提出\n店内均可使用，仅限堂食",
                           "date_info": {
                               "type": "DATE_TYPE_FIX_TIME_RANGE",
                               "begin_timestamp": '.time().' ,
                               "end_timestamp": '. (time()+720000) .'
                           },
                           "sku": {
                               "quantity": 500000
                           },
                           "get_limit": 3,
                           "use_custom_code": true,
                           "bind_openid": false,
                           "can_share": true,
                           "can_give_friend": true,
                           "custom_url_name": "立即使用",
                           "custom_url_sub_title": "6个汉字tips",
                           "promotion_url_name": "更多优惠",
                           "source": "大众点评"   
                       },
                       "deal_detail": "以下锅底2选1（有菌王锅、麻辣锅、大骨锅、番茄锅、清补凉锅、酸菜鱼锅可选）：\n大锅1份 12元\n小锅2份 16元 "}
                 }
            }';
        
        $result = Wx::createCard($this->trimall($card_json));
        var_dump($result);
        //创建微信卡券
    }
    /*
     * 创建团购券
     */
    public function createGroupon() {
    }

    /*
     * 创建团购券
     */
    public function createGroupon() {
    }
}
